home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 033a / mxtms_10.zip / FILE.C < prev    next >
C/C++ Source or Header  |  1991-05-27  |  3KB  |  123 lines

  1. /****************************************************************************/
  2. /*                                                                          */
  3. /*    File.c       Version 1.0    By Craig Derouen                          */
  4. /*                 A Maximus CBBCS Timebank program                         */
  5. /*                                                                          */
  6. /*                                                                          */
  7. /****************************************************************************/
  8.  
  9.  
  10. #include "maxtime.h"
  11. #include "globals.h"
  12.  
  13. struct user_cfg uscfg;
  14.  
  15. /* Find the user in the config file */
  16.  
  17. int find_config(int handle,char *name,struct user_cfg *uscfg)
  18. {
  19.    int x,y;
  20.  
  21.    x = 0;
  22.    lseek(handle,0L,SEEK_SET);        /* Rewind to begginning */
  23.    while (1) {
  24.       y = read(handle,(char *) uscfg,sizeof(struct user_cfg));
  25.       if( y < sizeof(struct user_cfg)) 
  26.          return(-1);
  27.       if (strcmpi(uscfg->name,name) == 0) { /* It's found! */
  28.          return(x);
  29.       }
  30.       x++;        /* Try next user */
  31.    }
  32. }
  33.  
  34. /* Find a blank slot in the config file */
  35.  
  36. int find_blconfig(int handle)
  37. {
  38.    int x,y;
  39.    struct user_cfg uscfg;
  40.  
  41.    x = 0;
  42.    lseek(handle,0L,SEEK_SET);        /* Rewind to begginning */
  43.    while (1) {
  44.       y = read(handle,(char *) &uscfg,sizeof(struct user_cfg));
  45.       if( y < sizeof(struct user_cfg)) 
  46.          return(-1);
  47.       if (uscfg.isused == 0)  /* It's found! */
  48.          return(x);
  49.       x++;        /* Try next user */
  50.    }
  51. }
  52.  
  53. void newuser_help(void)
  54. {
  55.    setcolor(TextAttr[STD_TEXT]);
  56.    if(show_file(NewHelpFil) >= 0) {
  57.       setcolor(TextAttr[HILITE_TEXT]);
  58.       strout("\r\n\r\nPress any key to exit.");
  59.       chrinwait(1);
  60.       strout("\r\n");
  61.    }
  62. }
  63.  
  64. int show_file(char *strng)
  65. {
  66.    FILE *newfile;
  67.    int linecount;
  68.    char ltemp[81];
  69.  
  70.    if (strng[0] == '\0')
  71.       return(-1);        /* No help file */
  72.  
  73.    newfile = _fsopen(strng,"r",SH_DENYNO);        /* Open in read only, text mode */
  74.    if (newfile == NULL) {
  75.       sprintf(ltemp,"Error opening %s file for user.",strng);
  76.       logit(ltemp,'!');
  77.       return(-1);        /* Just skip it */
  78.    }
  79.  
  80.    linecount = 0;
  81.    while (!feof(newfile)) {
  82.       if(fgets(ltemp,80,newfile)) {
  83.          if (linecount > 22) {        /* Turn on more for paging */
  84.             strout("\r\n\r\nPress any key for more");
  85.             chrinwait(1);
  86.             strout("\r\n");
  87.             linecount = 0;
  88.          }
  89.          strout(ltemp);
  90.          strout("\r");
  91.          linecount++;
  92.       }
  93.    }
  94.    fclose(newfile);
  95.    return(0);
  96. }
  97.  
  98. int new_user(int filenum)
  99. {
  100.    int x,y;
  101.    struct user_cfg uscfg;
  102.  
  103.    x = 0;
  104.  
  105. /* Seek to start of file and count records */
  106.    if(lseek(filenum,0L,SEEK_SET) >= 0L)     {    /* Rewind to begginning */
  107.       y = read(filenum,(char *) &uscfg,sizeof(struct user_cfg));
  108.       while (y == sizeof(struct user_cfg)) {
  109.          x++;        /* Simple count */
  110.          y = read(filenum,(char *) &uscfg,sizeof(struct user_cfg));
  111.       }
  112.    }
  113.    return(x);
  114. }
  115.  
  116. void update_usercfg(int filenum)
  117. {
  118.    lseek(filenum,(long) (UserCfgnum * sizeof(struct user_cfg)),SEEK_SET);        /* Append to tail of file */
  119.    write(filenum,(struct user_cfg *) &USERCFG,sizeof(struct user_cfg));
  120. }
  121.  
  122.  
  123.